﻿using Microsoft.Practices.Unity.InterceptionExtension;
using System;
using System.Collections.Generic;
using iTelluro.Explorer.Infrastructure.CrossCutting.Logging;

namespace ByteartRetail.Infrastructure.InterceptionBehaviors
{
    /// <summary>
    /// 表示用于异常日志记录的拦截行为。
    /// </summary>
    public class ExceptionLoggingBehavior : ICallHandler
    {
        #region ICallHandler 成员

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            var methodReturn = getNext().Invoke(input, getNext);
            if (methodReturn.Exception != null)
            {
                LoggerFactory.CreateLog().LogError("方法:" + input.MethodBase.Name + "出现异常", methodReturn.Exception);
            }
            return methodReturn;
        }

        public int Order
        {
            get;
            set;
        }

        #endregion
    }
}
